package com.nbjtjc.safe.service.edu;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
//import com.github.pagehelper.PageHelper;
//import com.github.pagehelper.PageInfo;
//import com.nbjtjc.safe.bean.Page;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.edu.EduUserMapper;
import com.nbjtjc.safe.model.edu.EduUser;

//import com.xiaoleilu.hutool.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EduUserService {
	@Autowired
    private EduUserMapper eduUserMapper;
	
    public Result add(EduUser eduUser){
	        Result result=new Result();
	        if(ObjectUtil.isNull(eduUser)
	                ){
	            result.setFalse("用户数据不能为空");
	            return result;
	        }
//	        ||ObjectUtil.isNull(eduUser.getId())
	        if( ObjectUtil.isNull(eduUser.getId()) || ObjectUtil.isNull(eduUserMapper.selectByPrimaryKey(eduUser.getId()))){
	        	int res=eduUserMapper.insertSelective(eduUser);
	     
		        if(res==0){
		            result.setFalse("插入失败");
		            return result;
	
		        }
	        }else
	        {
	        	int res=eduUserMapper.updateByPrimaryKeySelective(eduUser);
	        	 if(res==0){
	        		 result.setFalse("更新失败");
	 	            return result;

	        	 }
	        }
	        result.setData(eduUser);

	        return result;
	    }
    
    
    public Result delete(Integer eduUserId){
        Result result=new Result();
        if(ObjectUtil.isNull(eduUserId)){
            result.setFalse("删除对象不能为空");
            return result;
        }
        int res = eduUserMapper.deleteByPrimaryKey(eduUserId);
	   	if(res==0){
		result.setFalse("更新失败");
	        return result;
	
		}
        return result;
    }

    public Result find(EduUser user) {
        Result result = new Result();
        PageHelper.startPage(user.getPageCurrent(), user.getPageSize());

        List<EduUser> eduUsers = eduUserMapper.select(user);
        result.setData(new PageInfo<>(eduUsers));

        return result;
    }
}
